package com.ilarele.shopping;

import java.io.Serializable;

public class Product implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 494367678934791631L;
	public String idProd;
	public long date;

	public float pointsTrust;
	public float pointsTags;

	public ProductPicture pPicture;
	public ProductName pName;
	public ProductInfo pInfo;
	public ProductTag pTags;
	public ProductComment pComments;

	public Product() {
		pPicture = new ProductPicture();
		pName = new ProductName();
		pInfo = new ProductInfo();
		pTags = new ProductTag();
		pComments = new ProductComment(); // used to send comment
	}

	public void nextNameRate() {
		if (pName.unsavedRate != 1)
			pName.unsavedRate++;
		else
			pName.unsavedRate = -1;
	}

	public void nextInfoRate() {
		if (pInfo.unsavedRate != 1)
			pInfo.unsavedRate++;
		else
			pInfo.unsavedRate = -1;

	}

	public void nextTagsRate() {
		if (pTags.unsavedRate != 1)
			pTags.unsavedRate++;
		else
			pTags.unsavedRate = -1;
	}

	public void nextImageRate() {
		if (pPicture.unsavedRate != 1)
			pPicture.unsavedRate++;
		else
			pPicture.unsavedRate = -1;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((idProd == null) ? 0 : idProd.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Product other = (Product) obj;
		if (idProd == null) {
			if (other.idProd != null)
				return false;
		} else if (!idProd.equals(other.idProd))
			return false;
		return true;
	}

}
